/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.database.bean;

import com.database.dao.CargoDao;
import com.database.dao.impl.CargoDaoImplement;
import com.database.model.Cargo;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author diego y Yinna
 */
@ManagedBean(name="cargoBean")
@SessionScoped
public class CargoBean {

   private Cargo cargo;
   private List<Cargo> cargos;
    
    
    public CargoBean() {
    }
    
     public Cargo getCargo() {
        
        if(cargo==null){
            cargo=new Cargo();
        }
        return cargo;
    }

    public void setArea(Cargo cargo) {
        this.cargo = cargo;
    }

    public List<Cargo> getCargos() {
        CargoDao cargoDao = new CargoDaoImplement(); 
        cargos= cargoDao.buscarTodos();
        return cargos;
    }
    
     public void preparInsertar(){
        cargo = new Cargo();
    }
    
     public void prepararActualizar(Integer id){
         CargoDao cargoDao = new CargoDaoImplement();
         cargo= cargoDao.buscarPorId(id);
    }
     
     public void prepararEliminar(Integer id){
         CargoDao cargoDao = new CargoDaoImplement();
         cargo= cargoDao.buscarPorId(id);
    }
    
    public void insertar(){
         
         CargoDao cargoDao = new CargoDaoImplement();
         cargoDao.insertar(cargo);
         cargo = new Cargo();
    }
    
     public void actualizar(){
         CargoDao cargoDao = new CargoDaoImplement();
         cargoDao.actualizar(cargo);
         cargo = new Cargo();
    }
     
     public void eliminar(){
         CargoDao cargoDao = new CargoDaoImplement();
         cargoDao.eliminar(cargo); 
         cargo = new Cargo();
     }
     
}
